<template>
    <div class="gray">
        <search></search>
        <img src="@/assets/page.png" width="100%" height="140">
        <div class="sortnav">
            <p :class="red == 'default' ? 'active' : ''"  @click="defu">综合</p>
            <div class="price">
                <p :class="red == 'price' ? 'active' : ''" @click="price">价格</p>
                <div class="chui">
                    <van-icon name="arrow-up" :class="current == 'up' ? 'active' : '' "/>
                    <van-icon name="arrow-down"  :class="current == 'down' ? 'active' : ''" />
                </div>
            </div>
            <p :class="red == 'category' ? 'active' : ''" @click="category">分类</p>
        </div>
        <ul>
            <li v-for="item in list" :key="item.id">
                <img :src="item.list_pic_url" width="151" height="151">
                <p>{{item.name}}</p>
                <p>￥{{item.retail_price}}</p>
            </li>
        </ul>
      
    </div>
</template>

<script>
import search from "@/components/search"
import { goodsList } from "@/api/home/index.js"

export default {
    data() {
        return {
            list:[],
            red:'default',
            current:"default",
            order:''
        };
    },
    methods: {
        init(){
            var id = this.$route.query.ids;
            goodsList({
                isHot:id==1 ? "1" : "",
                isNew:id==0 ? "1" : "",
                order:this.order
            }).then(res=>{
                console.log(res);
                this.list = res.data.data
            })
        },
        defu(){
            this.red = 'default';
            this.current = 'default';
            this.init();
        },
        price(){
            this.red = 'price';
            if(this.current == 'up'){
                this.current = 'down';
                this.order = 'desc';
                this.init();
            }else{
                this.current = 'up';
                this.order = 'asc';
                this.init();
            }
        },
        category(){
            this.red = 'category';
            this.current = 'default';
            this.init();
        }
    },
    created() {
        this.init();
    },
    computed: {
        
    },
    mounted() {

    },
    components:{
        search
    }
};
</script>

<style scoped lang="scss">
.gray{
    background-color: rgb(244,244,244);
}
.sortnav{
    display: flex;
    align-items: center;
    background-color: #fff;
    p{
        width: 33%;
        text-align: center;
    }
    .price{
       width: 33%;
       display: flex;
       justify-content: center;
       align-items: center;
       p{
           margin: 0;
       } 
       .chui{
           display: flex;
           flex-direction: column;
            justify-content: center;
            align-items: center;
            i{
                width: 10px;
                height: 10px;
            }
       }
    }
}
ul{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 10px;
    li{
        width: 49.5%;
        margin-bottom:1% ;
        background-color: #fff;
        p:last-child{
            font-size: .4rem;
            color: #b4282d;
        }
    }
}
.active{
    color: #b4282d;
}
</style>
